<template>
  <el-drawer :visible.sync="drawer" direction="rtl" size="45%" :with-header="false" :width="700">
    <div class="drawer_box">
      <div class="drawer_t">
        <div class="drawer_t_l">
          <img class="drawer_t_l_img" src="../../../../../static/skin/herodoo/main/platform/home/img/quanyishaixuan.png"
            alt="">
          权益筛选
        </div>
        <img class="drawer_t_r" src="../../../../../static/skin/herodoo/main/platform/home/img/guanbi.png" alt=""
          @click="drawer = false">
      </div>
      <div class="drawer_c">
        <div class="drawer_c_title">
          <img src="../../../../../static/skin/herodoo/main/platform/home/img/shaixuannr.png" alt=""
            class="drawer_c_title_img">
          筛选内容
        </div>
        <div class="exhibition">
          <div class="exhibition_title">所选内容:</div>
          <div class="exhibition_content">
            <div class="exhibition_content_list" v-for="(item) in typeArr" :key="item"
              @click="deleteExhibition(item, 1)">
              <div class="content_list_name">{{ item }}</div>
              <img class="content_list_img" src="../../../../../static/skin/herodoo/main/platform/home/img/shanchud.png"
                alt="">
            </div>
            <div class="exhibition_content_list" v-for="(item) in labelArr" :key="item"
              @click="deleteExhibition(item, 2)">
              <div class="content_list_name">{{ item }}</div>
              <img class="content_list_img" src="../../../../../static/skin/herodoo/main/platform/home/img/shanchud.png"
                alt="">
            </div>
            <div class="exhibition_content_list" v-for="(item) in priceArr" :key="item"
              @click="deleteExhibition(item, 3)">
              <div class="content_list_name">{{ item }}</div>
              <img class="content_list_img" src="../../../../../static/skin/herodoo/main/platform/home/img/shanchud.png"
                alt="">
            </div>
            <div class="exhibition_content_list" v-for="(item) in dataArr" :key="item"
              @click="deleteExhibition(item, 4)">
              <div class="content_list_name">{{ item }}</div>
              <img class="content_list_img" src="../../../../../static/skin/herodoo/main/platform/home/img/shanchud.png"
                alt="">
            </div>
            <div class="exhibition_content_list" v-for="(item) in compnyTypeArr" :key="item"
              @click="deleteExhibition(item, 5)">
              <div class="content_list_name">{{ item }}</div>
              <img class="content_list_img" src="../../../../../static/skin/herodoo/main/platform/home/img/shanchud.png"
                alt="">
            </div>
            <div class="exhibition_content_list" v-for="(item) in scaleArr" :key="item"
              @click="deleteExhibition(item, 6)">
              <div class="content_list_name">{{ item }}</div>
              <img class="content_list_img" src="../../../../../static/skin/herodoo/main/platform/home/img/shanchud.png"
                alt="">
            </div>
            <div class="exhibition_content_list" v-for="(item) in fundArr" :key="item"
              @click="deleteExhibition(item, 7)">
              <div class="content_list_name">{{ item }}</div>
              <img class="content_list_img" src="../../../../../static/skin/herodoo/main/platform/home/img/shanchud.png"
                alt="">
            </div>
            <div class="exhibition_content_list" v-for="(item) in industryArr" :key="item.ID"
              @click="deleteExhibition(item, 8)">
              <div class="content_list_name">{{ item.label }}</div>
              <img class="content_list_img" src="../../../../../static/skin/herodoo/main/platform/home/img/shanchud.png"
                alt="">
            </div>
            <div class="exhibition_content_list" v-for="(item) in statusArr" :key="item.ID"
              @click="deleteExhibition(item, 9)">
              <div class="content_list_name">{{ item }}</div>
              <img class="content_list_img" src="../../../../../static/skin/herodoo/main/platform/home/img/shanchud.png"
                alt="">
            </div>
          </div>
          <div class="clear" @click="clear">一键清空</div>
        </div>
      </div>
      <div class="drawer_l">
        <div class="exhibition">
          <div class="exhibition_title">审核状态:</div>
          <div class="drawer_l_content">
            <el-checkbox-group v-model="statusArr">
              <el-checkbox v-for="(item, index) in statusClass" :key="index" :label="item.Name"></el-checkbox>
            </el-checkbox-group>
          </div>
        </div>
        <div class="exhibition">
          <div class="exhibition_title">权益类型:</div>
          <div class="drawer_l_content">
            <el-checkbox-group v-model="typeArr">
              <el-checkbox v-for="(item, index) in typeClass" :key="index" :label="item.Name"></el-checkbox>
            </el-checkbox-group>
          </div>
        </div>
        <div class="exhibition">
          <div class="exhibition_title">权益价格:</div>
          <div class="drawer_l_content">
            <div class="customize_price">
              <div>自定义价格：</div>
              <div><input v-model="priceStar" placeholder="请输入金额" type="text"><span>至</span><input v-model="priceEnd"
                  placeholder="请输入金额" type="text"></div>
            </div>
            <el-checkbox-group v-model="priceArr" @change="scalecPriceChange">
              <el-checkbox v-for="(item, index) in priceClass" :key="index" :label="item"></el-checkbox>
            </el-checkbox-group>
          </div>
        </div>
        <div class="exhibition">
          <div class="exhibition_title">权益标签:</div>
          <div class="drawer_l_content">
            <el-checkbox-group v-model="labelArr">
              <el-checkbox v-for="(item, index) in labelClass" :key="index" :label="item.Name"></el-checkbox>
            </el-checkbox-group>
          </div>
        </div>
        <div class="exhibition">
          <div class="exhibition_title">采购公司限制:</div>
          <div class="drawer_l_content">

            <div class="content_list">
              <div class="nav_box">
                <div class="nav_title">公司类型:</div>
                <div class="nav_content">
                  <el-checkbox-group v-model="compnyTypeArr" @change="scalecompnyTypeChange">
                    <el-checkbox v-for="(item, index) in compnyTypeClass" :key="index" :label="item.Name"></el-checkbox>
                  </el-checkbox-group>
                </div>
              </div>
              <div class="nav_box">
                <div class="nav_title">公司规模:</div>
                <div class="nav_content">
                  <el-checkbox-group v-model="scaleArr" @change="scaleLadderChange">
                    <el-checkbox v-for="(item, index) in scaleClass" :key="index" :label="item.Name"></el-checkbox>
                  </el-checkbox-group>
                </div>
              </div>
              <div class="nav_box">
                <div class="nav_title">注册资金:</div>
                <div class="nav_content">
                  <el-checkbox-group v-model="fundArr" @change="fundLadderChange">
                    <el-checkbox v-for="(item, index) in fundClass" :key="index" :label="item.Name"></el-checkbox>
                  </el-checkbox-group>
                </div>
              </div>
              <div class="nav_box">
                <div class="nav_title">公司行业:</div>
                <div class="nav_content">
                  <el-tree ref="tree" :data="industryData" :props="defaultProps" node-key="ID" show-checkbox
                    default-expand-all @check="handleCheck"></el-tree>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
      <div class="drawer_b">
        <span class="drawer_sx" @click="search">
          筛选
        </span>
      </div>
    </div>
  </el-drawer>
</template>

<script>
export default {
  name: 'screenRights',
  data() {
    return {
      octopus: this.$parent.octopus,
      // 审核状态
      statusClass: [],
      statusArr: [],
      // 权益类型
      typeClass: [],
      typeArr: [],
      // 权益标签
      labelClass: [],
      labelArr: [],
      priceClass: ['0-100元', '101-300元', '301-500元', '501-1000元', '1000元以上'],
      priceArr: [],
      dataClass: ['01月', '02月', '03月', '04月', '05月', '06月', '07月', '08月', '09月', '10月', '11月', '12月'],
      dataArr: [],
      // 公司类型
      compnyTypeClass: [],
      compnyTypeArr: [],
      // 公司规模
      scaleClass: [],
      scaleArr: [],
      // 注册资金
      fundClass: [],
      fundArr: [],
      // 公司行业
      industryData: [],
      industryArr: [],
      minIndustryArr: [],
      drawer: false,
      // 价格区间
      priceStar: '',
      priceEnd: '',
      value1: '',
      dateData: []
    };
  },

  mounted() {
  },
  created() {
    this.init()
  },
  methods: {
    init() {
      let o = this
      // 审核状态
      this.octopus.request.api.post(
        "/Octopus/Engine/List",
        {
          id: 1194,
          cellData: [
            { name: "ID" },	// ID
            { name: "Name" },	// Name
          ],
        },
        function (data) {
          if (data.status.code == 200) {
            o.statusClass = data.content.queryData
          } else {
            o.octopus.tips.error(data);
          }
        });
      // 权益标签
      this.octopus.request.api.post(
        "/Octopus/Engine/List",
        {
          id: 774,
          cellData: [
            { name: "ID" },	// ID
            { name: "Name" },	// Name
          ],
        },
        function (data) {
          if (data.status.code == 200) {
            o.labelClass = data.content.queryData
          } else {
            o.octopus.tips.error(data);
          }
        });
      // 权益类型
      this.octopus.request.api.post(
        "/Octopus/Engine/List",
        {
          id: 753,
          cellData: [
            { name: "ID" },	// ID
            { name: "Name" },	// Name
          ],
        },
        function (data) {
          if (data.status.code == 200) {
            o.typeClass = data.content.queryData
          } else {
            o.octopus.tips.error(data);
          }
        });
      // 公司类型
      this.octopus.request.api.post(
        "/Octopus/Engine/List",
        {
          id: 820,
          cellData: [
            { name: "ID" },	// ID
            { name: "Name" },	// Name
          ],
        },
        function (data) {
          if (data.status.code == 200) {
            o.compnyTypeClass = data.content.queryData
          } else {
            o.octopus.tips.error(data);
          }
        });
      // 公司规模
      this.octopus.request.api.post(
        "/Octopus/Engine/List",
        {
          id: 822,
          cellData: [
            { name: "ID" },	// ID
            { name: "Name" },	// Name
          ],
        },
        function (data) {
          if (data.status.code == 200) {
            o.scaleClass = data.content.queryData
          } else {
            o.octopus.tips.error(data);
          }
        });
      // 公司行业
      this.octopus.request.api.post(
        "/Octopus/Engine/List",
        {
          id: 797,
          cellData: [
            { name: "ID" },	// ID
            { name: "Name" },	// Name
            { name: "ParentkeyValue" },	// 父ID
          ],
          pageData: {
            rowSize: 777
          },
        },
        function (data) {
          if (data.status.code == 200) {
            let prentArr = []
            data.content.queryData.forEach(element => {
              element.label = element.Name
              delete element.Name
              if (element.ParentkeyValue == null) {
                prentArr.push(element)
              }
            });
            prentArr.forEach(res => {
              res.children = []
            })
            data.content.queryData.forEach(res => {
              prentArr.forEach(re => {
                if (res.ParentkeyValue && res.ParentkeyValue == re.ID) {
                  re.children.push(res)
                }
              })
            })
            o.industryData = prentArr
          } else {
            o.octopus.tips.error(data);
          }
        });
      // 注册资金
      this.octopus.request.api.post(
        "/Octopus/Engine/List",
        {
          id: 793,
          cellData: [
            { name: "ID" },	// ID
            { name: "Name" },	// Name
          ],
          pageData: {
            rowSize: 777
          },
        },
        function (data) {
          if (data.status.code == 200) {
            o.fundClass = data.content.queryData
          } else {
            o.octopus.tips.error(data);
          }
        });
    },
    // 一键清空
    clear() {
      this.statusArr = []
      this.typeArr = []
      this.labelArr = []
      this.priceArr = []
      this.dataArr = []
      this.compnyTypeArr = []
      this.scaleArr = []
      this.fundArr = []
      this.minIndustryArr = []
      this.industryArr = []
      this.$refs.tree.setCheckedKeys([]);
    },
    //删除所选权益
    deleteExhibition(item, ind) {
      if (ind == 1) {
        this.typeArr = this.typeArr.filter(items => items != item)
      } else if (ind == 2) {
        this.labelArr = this.labelArr.filter(items => items != item)
      } else if (ind == 3) {
        this.priceArr = this.priceArr.filter(items => items != item)
      } else if (ind == 4) {
        this.dataArr = this.dataArr.filter(items => items != item)
      } else if (ind == 5) {
        this.compnyTypeArr = this.compnyTypeArr.filter(items => items != item)
      } else if (ind == 6) {
        this.scaleArr = this.scaleArr.filter(items => items != item)
      } else if (ind == 7) {
        this.fundArr = this.fundArr.filter(items => items != item)
      } else if (ind == 8) {
        this.$refs.tree.setChecked(item, false);
        this.industryArr = this.industryArr.filter(items => items != item)
        this.minIndustryArr = this.minIndustryArr.filter(items => items != item.label)
      } else if(ind == 9) {
        this.statusArr = this.statusArr.filter(items => items != item)
      }
    },
    handleCheck(node, checkedNodes) {
      this.industryArr = []
      this.minIndustryArr = []
      checkedNodes.checkedNodes.forEach(ele => {
        if (ele.ID != 1) {
          this.industryArr.push(ele)
          this.minIndustryArr.push(ele.label)
        }
      });
    },
    handleClose(done) {
      this.drawer = false
    },
    drawerOp() {
      this.drawer = true
    },
    scaleLadderChange() {
      if (this.scaleArr.length > 1) {
        this.scaleArr.shift();
      }
    },
    fundLadderChange() {
      if (this.fundArr.length > 1) {
        this.fundArr.shift();
      }
    },
    scalecPriceChange() {
      if (this.priceArr.length > 1) {
        this.priceArr.shift();
      }
    },
    scalecompnyTypeChange() {
      if (this.compnyTypeArr.length > 1) {
        this.compnyTypeArr.shift();
      }
    },
    changeTime() {
      let dates = []
      if (this.value1) {
        this.value1.forEach(res => {
          // console.log(new Date(res).toISOString().slice(0, 10));
          dates.push(new Date(res).toISOString())
        });
        this.dateData = dates
      } else {
        this.dateData = []
      }

    },
    handleClear() {
      this.dateData = []
    },
    // 筛选
    search() {
      // 权益标签
      let labelID = this.labelClass.filter(item => this.labelArr.includes(item.Name)).map(item => item.ID);
      // 价格
      let price = ''
      if (this.priceStar && this.priceEnd) {
        price = [this.priceStar * 1, this.priceEnd * 1]
        this.priceArr = []
      } else {
        price = this.priceArr.join().split('元')[0].split('-')
      }
      // 权益类型
      let typeID = this.typeClass.filter(item => this.typeArr.includes(item.Name)).map(item => item.ID);
      // 公司类型
      let compnyTypeID = this.compnyTypeClass.filter(item => this.compnyTypeArr.includes(item.Name)).map(item => item.ID);
      // 公司规模
      let scaleID = this.scaleClass.filter(item => this.scaleArr.includes(item.Name)).map(item => item.ID);
      // 公司行业
      let industryArr = []
      this.industryData.forEach(res => {
        if (res.children.length) {
          res.children.forEach(ress => {
            this.industryArr.forEach(ind => {
              if (ress.label == ind.label) {
                industryArr.push(ress.ID)
              }
            })
          })
        } else {
          this.industryArr.forEach(ind => {
            if (res.label == ind.label) {
              industryArr.push(res.ID)
            }
          })
        }
      })
      // 注册资金
      let fundID = this.fundClass.filter(item => this.fundArr.includes(item.Name)).map(item => item.ID);
      let company = [...compnyTypeID, ...scaleID, ...industryArr, ...fundID]

      // 使用期限

      // 审核状态
      let statusType = this.statusClass.filter(item => this.statusArr.includes(item.Name)).map(item => item.ID);
      this.$emit('searchFun', labelID, typeID, price, company, this.dateData, statusType);
      this.drawer = false
    }
  },
};
</script>
<style scoped>
.clear {
  text-decoration: underline;
  position: absolute;
  font-size: 1.2rem;
  color: #898582;
  cursor: pointer;
  bottom: .5rem;
  right: 1rem;
}

.exhibition_content div {
  display: flex;
  align-items: center;
  background-color: #FBF8F9;
  height: 3rem;
  padding: 0 .4rem;
  margin: .4rem;
  color: #898582;
  font-size: 1.2rem;
  border-radius: 1rem;
}

.content_list_img {
  cursor: pointer;
  width: 2rem;
  height: 2rem;
}

>>>.el-checkbox {
  margin-top: 1.5rem;
  width: 25%;
  padding-left: 1rem;
  margin-right: 0;
}

>>>.el-tree .el-checkbox__inner {
  margin-bottom: 1rem;
  width: 1.6rem;
  height: 1.6rem;
  /* vertical-align: top; */
}

.navsIndex {
  z-index: 10 !important;
}

.drawer_box {
  padding: 3rem 1.5rem;
  height: 100%;
  display: flex;
  flex-direction: column;
}

.drawer_t {
  display: flex;
  justify-content: space-between;
}

.drawer_t_l {
  display: flex;
  align-items: center;
  font-size: 1.8rem;
  font-weight: bold;
}

.drawer_t_l_img {
  width: 1.4vw;
  margin-right: 1vh;
}

.drawer_t_r {
  width: 3rem;
  height: 3rem;
  cursor: pointer;
}

.drawer_c {
  border-radius: 1rem;
  margin: 2rem 0;
  padding: 2rem;
  padding-bottom: 0;
  box-shadow: inset 0px 0px 4px 0px #E9E9E9;
  background: #FDFDFD;
}

.drawer_l {
  border-radius: 1rem;
  padding: 0 2rem;
  padding-bottom: 0;
  box-shadow: inset 0px 0px 4px 0px #E9E9E9;
  background: #FDFDFD;
  height: 58vh;
  padding-bottom: 1rem;
  box-sizing: border-box;
  overflow: auto;
}

.drawer_c_title {
  display: flex;
  align-items: center;
  font-weight: bold;
  font-size: 1.8rem;
}

.drawer_c_title_img {
  width: 3rem;
  height: 3rem;
}

.exhibition {
  display: flex;
  justify-content: space-between;
  margin: 2rem 0;
  position: relative;
}

.exhibition_title {
  font-size: 1.6rem;
}

.exhibition_content {
  display: flex;
  flex-wrap: wrap;
  max-height: 10rem;
  height: 10rem;
  overflow: auto;
  background-color: #fff;
  border: 1px solid #EBEBEB;
  width: 85%;
  border-radius: 1rem;
  padding: .2rem;
}

.drawer_l_content {
  display: flex;
  flex-wrap: wrap;
  overflow: auto;
  background-color: #fff;
  border: 1px solid #EBEBEB;
  width: 85%;
  border-radius: 1rem;
  padding: .2rem;
  padding-bottom: 2rem;
  font-size: 1.6rem;
}

.drawer_l_content .customize_price {
  margin-top: 1rem;
  line-height: 3rem;
  /* padding-right: 1rem; */
  margin-left: 1rem;
}

.drawer_l_content .customize_price input {
  border: 1px solid #EBEBEB;
  padding: 0 1rem;
  border-radius: .5rem;
}

.drawer_l_content .customize_price input::placeholder {
  font-size: 1.6rem;
  /* 设置你想要的字体大小 */
}

.drawer_l_content .customize_price span {
  margin: 0 1rem;
}

.nav_title {
  margin-top: 2rem;
  padding-left: 1rem;
}

.drawer_b {
  height: 4rem;
  display: flex;
  position: absolute;
  bottom: 1rem;
  right: 1.6rem;
  justify-content: end;
}

.drawer_sx {
  padding: 1rem 4rem;
  background-color: #F78C51;
  color: #fff;
  font-size: 1.6rem;
  border-radius: 1rem;
  cursor: pointer;
}

>>>.el-checkbox__label {
  font-size: 1.5rem;
}

>>>.el-checkbox__input.is-checked .el-checkbox__inner {
  background-color: #F78C51;
  border-color: #F78C51;
}

>>>.el-checkbox__input.is-indeterminate .el-checkbox__inner {
  background-color: #F78C51;
  border-color: #F78C51;
}

>>>.el-checkbox__input.is-checked+.el-checkbox__label {
  color: #F78C51;
}
</style>